#include <stdio.h>
#include <stdlib.h>

#define TABLE_SIZE 100

typedef struct
{
    int key;
    int value;
} Entry;

typedef struct
{
    Entry table[TABLE_SIZE];
} HashTable;

unsigned int hash(int key)
{
    return key % TABLE_SIZE;
}

void insert(HashTable *ht, int key, int value)
{
    unsigned int index = hash(key);
    while (ht->table[index].key != -1)
    {
        index = (index + 1) % TABLE_SIZE;
    }
    ht->table[index].key = key;
    ht->table[index].value = value;
}

void initialize(HashTable *ht)
{
    for (int i = 0; i < TABLE_SIZE; i++)
    {
        ht->table[i].key = -1;
    }
}

int search(HashTable *ht, int key)
{
    unsigned int index = hash(key);
    while (ht->table[index].key != -1)
    {
        if (ht->table[index].key == key)
        {
            return ht->table[index].value;
        }
        index = (index + 1) % TABLE_SIZE;
    }
    return -1;
}

void delete(HashTable *ht, int key)
{
    unsigned int index = hash(key);
    while (ht->table[index].key != -1)
    {
        if (ht->table[index].key == key)
        {
            ht->table[index].key = -1;
            return;
        }
        index = (index + 1) % TABLE_SIZE;
    }
}

int main(int argc, char const *argv[])
{
    // Test the hash table
    HashTable ht;
    initialize(&ht);
    insert(&ht, 1, 10);
    insert(&ht, 2, 20);
    insert(&ht, 3, 30);
    printf("%d\n", search(&ht, 2)); // Output: 20
    delete(&ht, 2);
    printf("%d\n", search(&ht, 2)); // Output: -1
    return 0;
}
